// app.js
import CryptoJS from  './utils/crypto-js.min.js'
const call = require("./utils/requests.js");
const util = require("./utils/util.js");
App({
  request: call,
  util: util,
  baseUrl:'http://127.0.0.1:8080/manager',
  onLaunch() {
    // 展示本地存储能力
    const rawText="abc";
    const encryptText=this.encryptData(rawText);

    console.log("abc加密后:",encryptText );
    const decryptText=this.decryptData(encryptText);
    console.log("abc加密后再解密:", decryptText);

    console.log(this.util.parseJsonObject('{"code":0,"msg":"操作成功","data":"http://127.0.0.1:80…s/20251024/e4962c647306492282898e72ccbe83fe.jpg"}'));
  },
  decryptData: function (encryptedData) {
    const cryptoKey="1234567890123456";
    //设置密钥
    const SELECT_KEY = CryptoJS.enc.Utf8.parse(cryptoKey);
    //const dataHex = CryptoJS.enc.Utf8.parse(data);
    const decrypted = CryptoJS.AES.decrypt({ciphertext: CryptoJS.enc.Base64.parse(encryptedData)},
    SELECT_KEY,
    {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7
    }
    );
    var rawText= decrypted.toString(CryptoJS.enc.Utf8);
    return (rawText==='-') ?'':rawText;
  },
  encryptData: function (data) {
    const cryptoKey="1234567890123456";
    //设置密钥
    const SELECT_KEY = CryptoJS.enc.Utf8.parse(cryptoKey);
    const dataHex = CryptoJS.enc.Utf8.parse(data);
    const encrypted = CryptoJS.AES.encrypt(dataHex, SELECT_KEY, {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7
    });
    return encrypted.toString((CryptoJS.format).Base64);
  },
  globalData: {
    isLogin: false,
    userInfo: null
  }
})
